﻿namespace Community.CsharpSqlite.Entity
{
    /*
     ** When a sub-program is executed (OPCode.OP_Program), a structure of this type
     ** is allocated to store the current value of the program counter, as
     ** well as the current memory cell array and various other frame specific
     ** values stored in the Vdbe struct. When the sub-program is finished, 
     ** these values are copied back to the Vdbe from the VdbeFrame structure,
     ** restoring the state of the VM to as it was before the sub-program
     ** began executing.
     **
     ** Frames are stored in a linked list headed at Vdbe.pParent. Vdbe.pParent
     ** is the parent of the current frame, or zero if the current frame
     ** is the main Vdbe program.
     */
    //typedef struct VdbeFrame VdbeFrame;
    public class VdbeFrame
    {
        public VdbeCursor[] aChildCsr; /* Array of cursors for child frame */
        public Mem[] aChildMem; /* Array of memory cells for child frame */
        public Mem[] aMem; /* Array of memory cells */
        public VdbeOp[] aOp; /* Program instructions */
        public VdbeCursor[] apCsr; /* Element of Vdbe cursors */
        public long lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
        public int nChange; /* Statement changes (Vdbe.nChanges)     */
        public int nChildCsr; /* Number of cursors for child frame */
        public int nChildMem; /* Number of memory cells for child frame */
        public ushort nCursor; /* Number of entries in apCsr */
        public int nMem; /* Number of entries in aMem */
        public int nOp; /* Size of aOp array */
        public VdbeFrame pParent; /* Parent of this frame */
        public int pc; /* Program Counter */
        public int token; /* Copy of SubProgram.token */
        public Vdbe v; /* VM this frame belongs to */
        //
        // Needed for C# Implementation
        //
    };
}